import request from "@/service/request";
import requestAly from '@/service/requestAly'
import {PromisePageResponse, PromiseResponse} from "@/service/api/type.ts";
import {CourseCategoryVo, CourseLabelVo, CourseSceneVo, UploadAuthVo} from "@/service/api/course/tag/types.ts";
/**
 * 获取所有标签
 * @param query
 */
const getTagList = (query: any): PromisePageResponse<CourseLabelVo> => {
  return request({
    url: "/course/label/list",
    method: "get",
    params: query,
  });
};

/**
 * 更新标签
 * @param query
 */
const updateLabel = (query: any): PromiseResponse<any> => {
  return request({
    url: "/course/label/edit",
    method: "put",
    data: query,
  });
};

/**
 * 删除标签
 * @param id
 */
const delLabel = (id: string | string[]): PromiseResponse<any> => {
  return request({
    url: `/course/label/${id}`,
    method: "delete",
  });
};

/**
 * 获取标签详情
 * @param id
 */
const getLabelDetail = (id: string): PromiseResponse<CourseLabelVo> => {
  return request({
    url: `/course/label/${id}`,
    method: "get",
  });
};

/**
 * 获取所有场景分类
 * @param query
 */
const getSceneList = (query: any): PromisePageResponse<CourseSceneVo> => {
  return request({
    url: "/course/scene/list",
    method: "get",
    params: query,
  });
};

/**
 * 新增一级分类
 * @param query
 */
const addFirstCategory = (query: any): PromiseResponse<any> => {
  return request({
    url: "/course/category/add",
    method: "post",
    data: query,
  });
};

/**
 * 新增二级分类
 * @param query
 */
const addSecondCategory = (query: any): PromiseResponse<any> => {
  return request({
    url: "/course/category/add",
    method: "post",
    data: query,
  });
};

/**
 * 根据场景id获取一级分类
 * @param sceneId
 * @param query
 */
const getFirstCategoryList = (sceneId: string, query: any): PromiseResponse<CourseCategoryVo[]> => {
  return request({
    url: `/course/category/listByScene/${sceneId}`,
    method: "get",
    params: query
  });
};

/**
 * 获取二级分类
 * @param query
 */
const getSecondCategoryList = (query: any): PromisePageResponse<CourseCategoryVo> => {
  return request({
    url: "/course/category/list",
    method: "get",
    params: query,
  });
};

/**
 * 根据分类id获取标签
 * @param categoryId
 */
const getLabelById = (categoryId: string,tagName: string): PromiseResponse<CourseLabelVo[]> => {
  return request({
    url: `/course/label/listByCategory/${categoryId}`,
    method: "get",
    params:{
      name:tagName
    }
  });
};

/**
 * 新增二级分类下的标签
 * @param query
 */
const addCategoryLabel = (query: any): PromiseResponse<any> => {
  return request({
    url: "/course/label/labelCategory",
    method: "post",
    data: query,
  });
};

/**
 * 标签库新增标签
 * @param query
 */
const addLabel = (query: any): PromiseResponse<any> => {
  return request({
    url: "/course/label",
    method: "post",
    data: query,
  });
};

/**
 * 批量新增二级分类下的标签
 * @param query
 */
const addLabelsToCategory = (query: any): PromiseResponse<any> => {
  return request({
    url: `/course/label/labelCategory/batch/${query.categoryId}`,
    method: "post",
    data: query.labelIds,
  });
};

/**
 * 新增场景
 * @param query
 */
const addScene = (query: any): PromiseResponse<any> => {
  return request({
    url: "/course/scene",
    method: "post",
    data: query,
  });
};

/**
 * 修改标签状态
 * @param query
 */
const updateLabelStatus = (query: any): PromiseResponse<any> => {
  return request({
    url: "/course/label/changeStatus",
    method: "put",
    data: query,
  });
};

/**
 * 移出分类下的标签
 * @param query
 */
const removeLabelsFromCategory = (query: any): PromiseResponse<any> => {
  return request({
    url: "/course/label/labelCategory",
    method: "delete",
    params: query,
  });
};

/**
 * 获取场景详情
 * @param id
 */
const getSceneDetail = (id: string): PromiseResponse<CourseSceneVo> => {
  return request({
    url: `/course/scene/${id}`,
    method: "get",
  });
};

/**
 * 获取分类详情
 * @param id
 */
const getCategoryDetail = (id: string): PromiseResponse<CourseCategoryVo> => {
  return request({
    url: `/course/category/${id}`,
    method: "get",
  });
};

/**
 * 修改场景分类信息
 * @param query
 */
const updateSceneDetail = (query: any): PromiseResponse<any> => {
  return request({
    url: "/course/scene/edit",
    method: "put",
    data: query,
  });
};

/**
 * 修改分类信息
 * @param query
 */
const updateCategoryDetail = (query: any): PromiseResponse<any> => {
  return request({
    url: "/course/category/edit",
    method: "post",
    data: query,
  });
};

/**
 * 删除场景
 * @param id
 */
const deleteScene = (id: string): PromiseResponse<any> => {
  return request({
    url: `/course/scene/${id}`,
    method: "delete",
  });
};

/**
 * 删除分类
 * @param id
 */
const deleteCategory = (id: string | string[]): PromiseResponse<any> => {
  return request({
    url: `/course/category/${id}`,
    method: "delete",
  });
};

/**
 * 改变场景状态
 * @param query
 */
const switchScene = (query: any): PromiseResponse<any> => {
  return request({
    url: "/course/scene/changeStatus",
    method: "put",
    data: query,
  });
};

/**
 * 改变分类状态
 */
const switchCategory = (query: any): PromiseResponse<any> => {
  return request({
    url: "/course/category/edit",
    method: "post",
    data: query,
  });
};

/**
 * 获取标签绑定的课程数
 * @param id
 */
const getLabelCourseCount = (id: string): PromiseResponse<number> => {
  return request({
    url: `/course/label/cntCourse/${id}`,
    method: "get",
  });
};

/**
 * 文件上传到OSS
 * @param File
 */
const postToOSS = (File: any) => {
  return requestAly({
    url: ``,
    method: "post",
    data: File,
  });
};

/**
 * 获取上传凭证
 * @param query
 */
const getOssAuth = (query: any): PromiseResponse<UploadAuthVo> => {
  return request({
    url: "/system/oss/uploadAuth",
    method: "get",
    params: query
  });
};

export {
  getTagList,
  getSceneList,
  addFirstCategory,
  getFirstCategoryList,
  getSecondCategoryList,
  addSecondCategory,
  getLabelById,
  addCategoryLabel,
  addScene,
  getLabelDetail,
  updateLabel,
  delLabel,
  addLabelsToCategory,
  updateLabelStatus,
  removeLabelsFromCategory,
  getSceneDetail,
  getCategoryDetail,
  updateSceneDetail,
  updateCategoryDetail,
  deleteScene,
  deleteCategory,
  switchScene,
  switchCategory,
  addLabel,
  getLabelCourseCount,
  postToOSS,
  getOssAuth
};
